<template>
  <div class="form">
    <el-form
      :inline="true"
      label-suffix="："
      :label-width="labelWidth"
      :size="size"
      ref="form"
    >
      <slot></slot>
      <div class="search-box">
        <el-button type="primary" icon="Search" @click="submit" :size="size"
          >搜索</el-button
        >
        <el-button type="info" icon="Refresh" @click="reset" :size="size"
          >重置</el-button
        >
      </div>
    </el-form>
  </div>
</template>

<script>
import { defineComponent } from "vue";
import { Search, Refresh } from "@element-plus/icons-vue";
export default defineComponent({
  components: {
    Search,
    Refresh,
  },
  emits:["submit","reset"],
  props: {
    size: {
      type: String,
      default: "small",
    },
    // 隐藏 清除筛选条件
    hideClean: {
      type: Boolean,
      default: false,
    },
    // 在清空筛选条件后提交
    submitAfterReset: {
      type: Boolean,
      default: false,
    },
    labelWidth: {
      type: String,
      default: "100px",
    },
  },
  data() {
    return {
      collapse: false,
    };
  },
  methods: {
    submit() {
      this.$emit("submit");
    },
    reset() {
      this.$emit("reset");
      if (this.submitAfterReset) {
        this.$emit("submit");
      }
    },
  },
  computed: {
    hasHiddenContent: function () {
      if (!this.$slots.hidden) {
        return false;
      }
      console.log("hidden", this.$slots.hidden);
      let slot = this.$slots.hidden();
      if (!slot) {
        return false;
      }
      if (slot.length != 0) {
        return true;
      }
      return false;
    },
  },
});
</script>

<style lang="scss" scoped>
.form {
  :deep(.el-form-item) {
    margin-right: 20px;
    margin-bottom: 8px;
  }
}
.clean {
  margin-left: 15px;
}
.collapse {
  transition: all 0.5s ease;
}
.rotate {
  // transition: all 0.5s ease;
  transform: rotate(-180deg);
}

.search-box {
  margin: 0 10px 8px 0;
  display: inline-flex;
  vertical-align: middle;
}
</style>
